home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / System 7.0 Samples / MacShell / Window2.c < prev   
Encoding:
C/C++ Source or Header  |  1991-12-04  |  7.1 KB  |  337 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** Program:     MacShell
  5. ** File:        window2.c
  6. ** Written by:  Eric Soldan
  7. **
  8. ** Copyright © 1990-1991 Apple Computer, Inc.
  9. ** All rights reserved.
  10. */
  11.  
  12.  
  13.  
  14. /*****************************************************************************/
  15.  
  16.  
  17.  
  18. #include "MacShell.h"            /* Get the MacShell includes/typedefs, etc.    */
  19. #include "MacShellCommon.h"        /* Get the stuff in common with rez.        */
  20. #include "MacShell.protos"        /* Get the prototypes for MacShell.            */
  21.  
  22. #ifndef __CTLHANDLER__
  23. #include "CtlHandler.h"
  24. #endif
  25.  
  26. #ifndef __ERRORS__
  27. #include <Errors.h>
  28. #endif
  29.  
  30. #ifndef __FONTS__
  31. #include <Fonts.h>
  32. #endif
  33.  
  34. #ifndef __LISTCONTROL__
  35. #include "ListControl.h"
  36. #endif
  37.  
  38. #ifndef __RESOURCES__
  39. #include <Resources.h>
  40. #endif
  41.  
  42. #ifndef __TEXTEDITCONTROL__
  43. #include "TextEditControl.h"
  44. #endif
  45.  
  46. #ifndef __TOOLUTILS__
  47. #include <ToolUtils.h>
  48. #endif
  49.  
  50. #ifdef THINK_C
  51. #include "Utilities.h"
  52. #else
  53. #ifndef __UTILITIES__
  54. #include <Utilities.h>
  55. #endif
  56. #endif
  57.  
  58.  
  59.  
  60. /*****************************************************************************/
  61.  
  62.  
  63.  
  64. extern short    gPrintPage;        /* Non-zero means we are printing. */
  65.  
  66.  
  67.  
  68. /*****************************************************************************/
  69. /*****************************************************************************/
  70.  
  71.  
  72.  
  73. /* This function adds the application's controls to a window. */
  74.  
  75. #pragma segment Window
  76. OSErr    InitContent(FileRecHndl frHndl, WindowPtr window)
  77. {
  78. #if MACSHELL_VERSION
  79.  
  80.     WindowPtr    oldPort;
  81.     short        i, mode;
  82.     Rect        ctlRect, brdrRect, viewRect, destRect;
  83.     TEHandle    teHndl, textBox[2];
  84.     Handle        text;
  85.     OSErr        err;
  86.  
  87.     err = noErr;
  88.  
  89.     GetPort(&oldPort);
  90.     SetPort(window);
  91.  
  92.     for (i = 0; i < 2; ++i) {
  93.         ctlRect = window->portRect;
  94.         --ctlRect.top;
  95.         --ctlRect.left;
  96.         ctlRect.right  -= 14;
  97.         ctlRect.bottom = ctlRect.top + (ctlRect.bottom - ctlRect.top + 1) / 2;
  98.         if (i) {
  99.             ctlRect.top = ctlRect.bottom - 1;
  100.             ctlRect.bottom = window->portRect.bottom + 1;
  101.         }
  102.         brdrRect = ctlRect;
  103.         viewRect = ctlRect;
  104.         InsetRect(&viewRect, 4, 4);
  105.         destRect = viewRect;
  106.         destRect.right -= 2;    /* This fixes a TextEdit problem where the
  107.                                 ** view has to be a little outside the dest on
  108.                                 ** the right, or else characters are clipped. */
  109.  
  110.         mode = i ? (cteVScrollLessGrow | cteActive) : (cteReadOnly + cteVScroll);
  111.         CTENew(rTECtl,        /* View ctl ResID used for TextEdit control.       */
  112.                window,        /* Window to hold TERecord.                           */
  113.                &teHndl,        /* Return handle for TERecord.                        */
  114.                &ctlRect,    /* Rect for view control.                           */
  115.                &destRect,    /* destRect for TERecord.                           */
  116.                &viewRect,    /* viewRect for TERecord.                           */
  117.                &brdrRect,    /* Used to frame a border.                           */
  118.                32000,        /* Maximum TextEdit document length.               */
  119.                mode            /* Read-only or read-write, vert scroll, grow box. */
  120.         );
  121.         if (!(textBox[i] = teHndl)) err = memFullErr;
  122.     }
  123.     (*frHndl)->doc.inBox  = textBox[0];
  124.     (*frHndl)->doc.outBox = textBox[1];
  125.  
  126.     if (text = (*frHndl)->doc.textHndl) {
  127.         text = CTESwapText(textBox[1], text, false);
  128.         DisposHandle(text);
  129.         (*frHndl)->doc.textHndl = nil;
  130.     }
  131.  
  132.     SetPort(oldPort);
  133.     return(err);
  134.  
  135. #else
  136. #pragma unused (frHndl, window)
  137.     return(noErr);
  138. #endif
  139.  
  140. }
  141.  
  142.  
  143.  
  144. /*****************************************************************************/
  145.  
  146.  
  147.  
  148. /* Image the document into the current port. */
  149.  
  150. #pragma segment Window
  151. void    ImageDocument(FileRecHndl frHndl)
  152. {
  153. #if MACSHELL_VERSION
  154.  
  155.     WindowPtr        thePort;
  156.     Rect            rct, theInk;
  157.     TEHandle        te;
  158.     short            pageCol;
  159.     static short    taskOffset, taskNum;
  160.  
  161.     GetPort(&thePort);
  162.  
  163.     if (!gPrintPage) {                                        /* If not printing... */
  164.         DoDrawControls(thePort, false);                        /* Draw the content controls. */
  165.     }
  166.     else {
  167.  
  168.         if (gPrintPage == 1) taskOffset = taskNum = 0;
  169.  
  170.         theInk = thePort->portRect;
  171.         InsetRect(&theInk, 4, 4);        /* Just so no characters get clipped. */
  172.  
  173.         pageCol = 0;
  174.         for (rct = theInk; taskNum < 2;) {
  175.             te = (taskNum) ? (*frHndl)->doc.outBox : (*frHndl)->doc.inBox;
  176.             CTEPrint(te, &taskOffset, &rct);
  177.             if (taskOffset != -1) return;    /* Text went to bottom of page. */
  178.             taskOffset = 0;                    /* Done with this TextEdit record. */
  179.             ++taskNum;
  180.             rct.top    = rct.bottom + 20;
  181.             rct.bottom = theInk.bottom;
  182.             if (rct.top + 20 >= rct.bottom) return;
  183.                 /* No page left or not enough to bother with. */
  184.         }
  185.         gPrintPage = 0;
  186.     }
  187.  
  188. #else
  189. #pragma unused (frHndl)
  190. #endif
  191.  
  192. }
  193.  
  194.  
  195.  
  196. /*****************************************************************************/
  197.  
  198.  
  199.  
  200. /* Resize application specific content  (Called by ResizeWindow). */
  201.  
  202. #pragma segment Window
  203. void    ResizeContent(WindowPtr window, short oldh, short oldv)
  204. {
  205. #if MACSHELL_VERSION
  206. #pragma unused (oldh, oldv)
  207.  
  208.     FileRecHndl    frHndl;
  209.     WindowPtr    oldPort;
  210.     short        i;
  211.     Rect        rct;
  212.     TEHandle    te;
  213.  
  214.     if (!window) return;
  215.  
  216.     frHndl  = (FileRecHndl)GetWRefCon(window);
  217.     oldPort = SetFilePort(frHndl);
  218.  
  219.     for (i = 0; i < 2; ++i) {
  220.         rct = window->portRect;
  221.         --rct.top;
  222.         --rct.left;
  223.         rct.right  -= 14;
  224.         rct.bottom = rct.top + (rct.bottom - rct.top + 1) / 2;
  225.         if (i) {
  226.             rct.top = rct.bottom - 1;
  227.             rct.bottom = window->portRect.bottom + 1;
  228.         }
  229.  
  230.         te = (i) ? (*frHndl)->doc.outBox : (*frHndl)->doc.inBox;
  231.         CTEMove(te, rct.left, rct.top);
  232.         CTESize(te, rct.right - rct.left, rct.bottom - rct.top, true);
  233.     }
  234.  
  235.     SetPort(oldPort);
  236.  
  237. #else
  238. #pragma unused (window, oldh, oldv)
  239. #endif
  240.  
  241. }
  242.  
  243.  
  244.  
  245. /*****************************************************************************/
  246.  
  247.  
  248.  
  249. /* Draw application specific content  (Called by DoDrawFrame). */
  250.  
  251. #pragma segment Window
  252. void    DrawFrame(FileRecHndl frHndl, WindowPtr window)
  253. {
  254. #pragma unused (frHndl, window)
  255. }
  256.  
  257.  
  258.  
  259. /*****************************************************************************/
  260.  
  261.  
  262.  
  263. /* Draw application specific frame area  (Called by DoCalcFrameRgn). */
  264.  
  265. #pragma segment Window
  266. void    CalcFrameRgn(FileRecHndl frHndl, WindowPtr window, RgnHandle rgn)
  267. {
  268. #pragma unused (frHndl, window, rgn)
  269. }
  270.  
  271.  
  272.  
  273. /*****************************************************************************/
  274.  
  275.  
  276.  
  277. /* This is called when a mouse-down event occurs in the content of a window.
  278. ** Other applications might want to call FindControl, TEClick, etc., to
  279. ** further process the click.
  280. */
  281.  
  282. #pragma segment Window
  283. void    ContentClick(WindowPtr window, EventRecord *event)
  284. {
  285.     FileRecHndl        frHndl;
  286.     ControlHandle    ctl;
  287.     short            dblClick;
  288.  
  289.     if (!IsAppWindow(window)) return;
  290.  
  291.     SetPort(window);
  292.  
  293.     if (IsCtlEvent(window, event, &ctl, &dblClick)) return;
  294.  
  295.     frHndl = (FileRecHndl)GetWRefCon(window);
  296.     if ((*frHndl)->fileState.readOnly) return;
  297.         /* Don't allow changes if read-only. */
  298. }
  299.  
  300.  
  301.  
  302. /*****************************************************************************/
  303.  
  304.  
  305.  
  306. /* This is called when a key event occurs and it is determined that it isn't
  307. ** a menu key.
  308. */
  309.  
  310. #pragma segment Window
  311. void    ContentKey(WindowPtr window, EventRecord *event)
  312. {
  313. #if MACSHELL_VERSION
  314.     short            ctlNum, action;
  315.     ControlHandle    ctl;
  316. #endif
  317.  
  318. #if MACSHELL_VERSION
  319.             if ((event->message & charCodeMask) == 0x03) {
  320.                 SendMessage((FileRecHndl)GetWRefCon(window), kTextMssg);
  321.                 return;
  322.             }
  323.             ctlNum = IsCtlEvent(window, event, &ctl, &action);
  324.             if (ctlNum == 2) {
  325.                 if (action) {
  326.                     SetWindowDirty(window);
  327.                     AdjustMenus();        /* Avoid unnecessary DoCursor() and speed */
  328.                 }                        /* up TextEdit entry. */
  329.                 return;
  330.             }
  331. #endif
  332.  
  333. }
  334.  
  335.  
  336.  
  337.